package com.simon.hse.activity.safe.jsa;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.simon.hse.MyApplication;
import com.simon.hse.R;
import com.simon.hse.activity.BaseActivity;
import com.simon.hse.activity.SignActivity;
import com.simon.hse.adapter.CommonAdapter;
import com.simon.hse.adapter.CommonEmptyAdapter;
import com.simon.hse.adapter.CommonViewHolder;

import org.xutils.view.annotation.ContentView;
import org.xutils.view.annotation.Event;
import org.xutils.view.annotation.ViewInject;

import java.util.ArrayList;
import java.util.List;

/**
 * 申请JSA分析
 */
@SuppressWarnings("all")
@ContentView(R.layout.activity_apply_jsa_analysis)
public class ApplyJsaAnalysisActivity extends BaseActivity {
    @ViewInject(R.id.tv_common_title)
    TextView mTv_common_title;

    @ViewInject(R.id.tv_apply_work_permit_xgbg)
    TextView mTv_apply_work_permit_xgbg;

    @ViewInject(R.id.ll_danger_stop_bottom)
    LinearLayout mLl_danger_stop_bottom;
    @ViewInject(R.id.tv_submission)
    TextView tvSubmission;
    @ViewInject(R.id.tv_save)
    TextView tvSave;
    @ViewInject(R.id.tv_cancel)
    TextView tvCancel;

    @ViewInject(R.id.recyclerview_risk)
    RecyclerView mRecyclerview_risk;

    @ViewInject(R.id.recyclerview_partake)
    RecyclerView mRecyclerview_partake;

    @ViewInject(R.id.tv_department)
    TextView tv_department;
    @ViewInject(R.id.ll_department)
    LinearLayout ll_department;

    @ViewInject(R.id.tv_approver)
    TextView tv_approver;
    @ViewInject(R.id.ll_approver)
    LinearLayout ll_approver;

    private boolean isShowBottom = false;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        mTv_common_title.setText("申请JSA分析");
        initRisk();
        initPartake();
//        Bundle bundle = getIntent().getExtras();
//        if (bundle == null) {
//            mLl_danger_stop_bottom.setVisibility(View.VISIBLE);
//            mTv_apply_work_permit_xgbg.setText("特殊作业许可证及相关附件信息");
//        } else {
//            mLl_danger_stop_bottom.setVisibility(View.INVISIBLE);
//            mTv_apply_work_permit_xgbg.setText("特殊作业许可证及相关表格");
//        }
    }

    @Event(value = {R.id.iv_common_left, R.id.iv_add_risk,R.id.iv_add_partake, R.id.tv_submission, R.id.tv_save, R.id.tv_cancel,R.id.iv_delete_partake
            , R.id.ll_department, R.id.ll_approver})
    private void finish(View view) {
        switch (view.getId()) {
            case R.id.iv_common_left:
                finish();
                break;
            case R.id.tv_submission:
                finish();
                break;
            case R.id.tv_save:
                finish();
                break;
            case R.id.iv_add_risk:
                startActivity(new Intent(ApplyJsaAnalysisActivity.this, RiskRecognitionAndSafeStepQuertListActivity.class));
                break;
            case R.id.iv_add_partake:
                startActivity(new Intent(ApplyJsaAnalysisActivity.this, SignActivity.class));
                break;
            case R.id.iv_delete_partake:
                break;
            case R.id.ll_department:
                initSafePop(ll_department, tv_department, MyApplication.getInstance().mSafeDepartmentList);
                break;
            case R.id.ll_approver:
                initSafePop(ll_approver, tv_approver, MyApplication.getInstance().mSafeApproverList);
                break;
        }
    }

    /**
     * 风险识别及安全措施
     */
    private void initRisk() {
        List<String> mList = new ArrayList<>();
        for (int i = 0; i < 5; i++) {
            mList.add("第" + i + "条数据");
        }

        LinearLayoutManager llm = new LinearLayoutManager(ApplyJsaAnalysisActivity.this);
        mRecyclerview_risk.setLayoutManager(llm);
        // 如果Item够简单，高度是确定的，打开FixSize将提高性能
        mRecyclerview_risk.setHasFixedSize(true);
        // 设置Item默认动画，加也行，不加也行
        mRecyclerview_risk.setItemAnimator(new DefaultItemAnimator());
        mRecyclerview_risk.setNestedScrollingEnabled(false);

        CommonAdapter mCommonEmptyAdapter = new CommonAdapter(ApplyJsaAnalysisActivity.this, R.layout.layout_risk_item, mList);
        mCommonEmptyAdapter.setItemDataListener(new CommonAdapter.ItemDataListener<String>() {
            @Override
            public void setItemData(CommonViewHolder holder, String dataBean) {
                // TextView tv_law_msg = holder.getView(R.id.tv_law_msg);

            }
        });

        mCommonEmptyAdapter.setOnItemClickListener(new CommonAdapter.OnItemClickListener() {
            @Override
            public void setOnItemClickListener(View view, int position) {

            }

            @Override
            public void setOnItemLongClickListener(View view, int position) {

            }
        });

        mCommonEmptyAdapter.setHasStableIds(true);
        mRecyclerview_risk.setAdapter(mCommonEmptyAdapter);
    }

    /**
     * 参与JSA分析人
     */
    private void initPartake() {
        List<String> mList = new ArrayList<>();
        for (int i = 0; i < 5; i++) {
            mList.add("第" + i + "条数据");
        }

        LinearLayoutManager llm = new LinearLayoutManager(ApplyJsaAnalysisActivity.this);
        mRecyclerview_partake.setLayoutManager(llm);
        // 如果Item够简单，高度是确定的，打开FixSize将提高性能
        mRecyclerview_partake.setHasFixedSize(true);
        // 设置Item默认动画，加也行，不加也行
        mRecyclerview_partake.setItemAnimator(new DefaultItemAnimator());
        mRecyclerview_partake.setNestedScrollingEnabled(false);

        CommonAdapter mCommonEmptyAdapter = new CommonAdapter(ApplyJsaAnalysisActivity.this, R.layout.layout_partake_item, mList);
        mCommonEmptyAdapter.setItemDataListener(new CommonAdapter.ItemDataListener<String>() {
            @Override
            public void setItemData(CommonViewHolder holder, String dataBean) {
                // TextView tv_law_msg = holder.getView(R.id.tv_law_msg);

            }
        });

        mCommonEmptyAdapter.setOnItemClickListener(new CommonAdapter.OnItemClickListener() {
            @Override
            public void setOnItemClickListener(View view, int position) {

            }

            @Override
            public void setOnItemLongClickListener(View view, int position) {

            }
        });

        mCommonEmptyAdapter.setHasStableIds(true);
        mRecyclerview_partake.setAdapter(mCommonEmptyAdapter);
    }
}
